package com.qf.java2007.web.controller;

import com.qf.java2007.pojo.Admin;
import com.qf.java2007.pojo.LendList;
import com.qf.java2007.service.LendListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author AzureSky_X
 * @Date 2021/3/10 14:35
 * @Version 1.0
 */
@Controller
@RequestMapping("/lend")
public class LendListController {
    @Autowired
    private LendListService lendListService;

    /**
     * 查看我的借还
     *
     * @param readerId
     * @return
     */
    @GetMapping("/mylend")
    public ModelAndView mylend(Long readerId) {
        //ReaderInfo readerInfo= readerCardService.findReaderCardById(readerId);
        List<LendList> lendLists = lendListService.findByReaderId(readerId);
        ModelAndView mav = new ModelAndView("reader_lend_list");
        mav.addObject("lendLists", lendLists);

        return mav;
    }

    /**
     * 查看所有借还日志
     *
     * @param
     * @return
     */
    @GetMapping("/lendlist")
    public ModelAndView lendList(String reNewPasswd, Long adminId) {
        List<LendList> lendLists = lendListService.findAllLendList();
        ModelAndView mav = new ModelAndView("admin_lend_list");
        mav.addObject("lendLists", lendLists);
        return mav;
    }

    /**
     * 删除借阅记录
     *
     * @param serNum
     * @return
     */
    @GetMapping("/deletelend")
    public ModelAndView deleteLend(Long serNum) {
        lendListService.deleteLengById(serNum);
        List<LendList> lendLists = lendListService.findAllLendList();
        ModelAndView mav = new ModelAndView("admin_lend_list");
        mav.addObject("lendLists", lendLists);
        mav.addObject("succ", "删除成功！！！");

        return mav;
    }

    /**
     * 借书
     *
     * @param
     * @return
     */
    @GetMapping("/borrowBook")
    public ModelAndView borrowBook(Long bookId, Long readerId, Integer number) {
        lendListService.borrowBook(bookId, readerId, number);
        List<LendList> lendLists = lendListService.findByReaderId(readerId);
        ModelAndView mav = new ModelAndView("reader_lend_list");
        mav.addObject("lendLists", lendLists);
        mav.addObject("succ", "借阅成功！！！");

        return mav;
    }


}
